package com.fanshuai2.niuke.monitor;

import java.util.*;

public class Data {
    static class Match {
        int index;
        int value;
        public Match(int index, int value) {
            this.index = index;
            this.value = value;
        }
    }

    static String output(int[] I, int[] R) {

        Set<Integer> set = new TreeSet<>();
        for (int r : R) {
            set.add(r);
        }

        Map<Integer, List<Match>> map = new LinkedHashMap<>();
        for (int r: set) {
            List<Match> list = new ArrayList<>();

            for (int i = 0; i < I.length; i++) {
                int v = I[i];
                if (String.valueOf(v).contains(String.valueOf(r))) {
                    Match match = new Match(i, v);
                    list.add(match);
                }
            }
            if (list.size() > 0) {
                map.put(r, list);
            }

        }

        int count = 0;
        StringBuilder b = new StringBuilder();
        for (Integer r: map.keySet()) {
            List<Match> list = map.get(r);
            b.append(r).append(" ").append(list.size()).append(" ");
            count += 2;

            for (Match match: list) {
                b.append(match.index).append(" ").append(match.value).append(" ");
            }
            count += list.size() * 2;
        }
        String s = b.toString();
        s = s.substring(0, s.length() - 1);
        return count + " " + s;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while (in.hasNextInt()) {

            int leni = in.nextInt();
            int[] I = new int[leni];
            for (int i = 0; i < leni; i++) {
                I[i] = in.nextInt();
            }
            int lenr = in.nextInt();
            int[] R = new int[lenr];
            for (int i = 0; i < lenr; i++) {
                R[i] = in.nextInt();
            }

            System.out.println(output(I, R));
        }
    }
}
